home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Visual Basic 5.0 (2nd Edition) / Hardcore Visual Basic 5.0 - Second Edition (1997)(Microsoft Press).iso / Code / Goodies / ICONWO~1 / COLORPAL.FRM < prev    next >
Text File  |  1997-06-09  |  16KB  |  471 lines

  1. VERSION 5.00
  2. Begin VB.Form ColorPalette 
  3.    BackColor       =   &H00FFFFFF&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "IconWorks Color Palette"
  6.    ClientHeight    =   3096
  7.    ClientLeft      =   1596
  8.    ClientTop       =   1932
  9.    ClientWidth     =   5664
  10.    ClipControls    =   0   'False
  11.    BeginProperty Font 
  12.       Name            =   "System"
  13.       Size            =   9.6
  14.       Charset         =   0
  15.       Weight          =   700
  16.       Underline       =   0   'False
  17.       Italic          =   0   'False
  18.       Strikethrough   =   0   'False
  19.    EndProperty
  20.    HelpContextID   =   1906
  21.    Icon            =   "COLORPAL.frx":0000
  22.    LinkMode        =   1  'Source
  23.    LinkTopic       =   "Form1"
  24.    MaxButton       =   0   'False
  25.    MinButton       =   0   'False
  26.    PaletteMode     =   1  'UseZOrder
  27.    ScaleHeight     =   3096
  28.    ScaleWidth      =   5664
  29.    Begin VB.PictureBox Pic_ColorPalette 
  30.       BackColor       =   &H00FFFFFF&
  31.       BeginProperty Font 
  32.          Name            =   "MS Sans Serif"
  33.          Size            =   7.8
  34.          Charset         =   0
  35.          Weight          =   700
  36.          Underline       =   0   'False
  37.          Italic          =   0   'False
  38.          Strikethrough   =   0   'False
  39.       EndProperty
  40.       ForeColor       =   &H00000000&
  41.       Height          =   1005
  42.       Left            =   60
  43.       ScaleHeight     =   960
  44.       ScaleWidth      =   5508
  45.       TabIndex        =   0
  46.       Top             =   60
  47.       Width           =   5550
  48.    End
  49.    Begin VB.HScrollBar Scrl_RGB 
  50.       Height          =   300
  51.       Index           =   0
  52.       LargeChange     =   10
  53.       Left            =   750
  54.       Max             =   255
  55.       TabIndex        =   4
  56.       Top             =   1260
  57.       Width           =   2550
  58.    End
  59.    Begin VB.TextBox Txt_RGB 
  60.       BackColor       =   &H00FFFFFF&
  61.       BeginProperty Font 
  62.          Name            =   "MS Sans Serif"
  63.          Size            =   7.8
  64.          Charset         =   0
  65.          Weight          =   700
  66.          Underline       =   0   'False
  67.          Italic          =   0   'False
  68.          Strikethrough   =   0   'False
  69.       EndProperty
  70.       ForeColor       =   &H00000000&
  71.       Height          =   300
  72.       Index           =   0
  73.       Left            =   3330
  74.       TabIndex        =   7
  75.       Top             =   1260
  76.       Width           =   480
  77.    End
  78.    Begin VB.PictureBox Pic_RGB 
  79.       BeginProperty Font 
  80.          Name            =   "MS Sans Serif"
  81.          Size            =   7.8
  82.          Charset         =   0
  83.          Weight          =   700
  84.          Underline       =   0   'False
  85.          Italic          =   0   'False
  86.          Strikethrough   =   0   'False
  87.       EndProperty
  88.       Height          =   420
  89.       Index           =   0
  90.       Left            =   3840
  91.       ScaleHeight     =   372
  92.       ScaleWidth      =   540
  93.       TabIndex        =   15
  94.       Top             =   1260
  95.       Width           =   585
  96.    End
  97.    Begin VB.PictureBox Pic_SelectedColor 
  98.       BeginProperty Font 
  99.          Name            =   "MS Sans Serif"
  100.          Size            =   7.8
  101.          Charset         =   0
  102.          Weight          =   700
  103.          Underline       =   0   'False
  104.          Italic          =   0   'False
  105.          Strikethrough   =   0   'False
  106.       EndProperty
  107.       Height          =   630
  108.       Left            =   4455
  109.       ScaleHeight     =   588
  110.       ScaleWidth      =   1152
  111.       TabIndex        =   10
  112.       Top             =   1440
  113.       Width           =   1200
  114.    End
  115.    Begin VB.PictureBox Pic_RGB 
  116.       BeginProperty Font 
  117.          Name            =   "MS Sans Serif"
  118.          Size            =   7.8
  119.          Charset         =   0
  120.          Weight          =   700
  121.          Underline       =   0   'False
  122.          Italic          =   0   'False
  123.          Strikethrough   =   0   'False
  124.       EndProperty
  125.       Height          =   420
  126.       Index           =   1
  127.       Left            =   3840
  128.       ScaleHeight     =   372
  129.       ScaleWidth      =   540
  130.       TabIndex        =   16
  131.       Top             =   1680
  132.       Width           =   585
  133.    End
  134.    Begin VB.HScrollBar Scrl_RGB 
  135.       Height          =   300
  136.       Index           =   1
  137.       LargeChange     =   10
  138.       Left            =   750
  139.       Max             =   255
  140.       TabIndex        =   5
  141.       Top             =   1740
  142.       Width           =   2550
  143.    End
  144.    Begin VB.TextBox Txt_RGB 
  145.       BackColor       =   &H00FFFFFF&
  146.       BeginProperty Font 
  147.          Name            =   "MS Sans Serif"
  148.          Size            =   7.8
  149.          Charset         =   0
  150.          Weight          =   700
  151.          Underline       =   0   'False
  152.          Italic          =   0   'False
  153.          Strikethrough   =   0   'False
  154.       EndProperty
  155.       ForeColor       =   &H00000000&
  156.       Height          =   300
  157.       Index           =   1
  158.       Left            =   3315
  159.       TabIndex        =   8
  160.       Top             =   1740
  161.       Width           =   480
  162.    End
  163.    Begin VB.PictureBox Pic_RGB 
  164.       BeginProperty Font 
  165.          Name            =   "MS Sans Serif"
  166.          Size            =   7.8
  167.          Charset         =   0
  168.          Weight          =   700
  169.          Underline       =   0   'False
  170.          Italic          =   0   'False
  171.          Strikethrough   =   0   'False
  172.       EndProperty
  173.       Height          =   420
  174.       Index           =   2
  175.       Left            =   3840
  176.       ScaleHeight     =   372
  177.       ScaleWidth      =   540
  178.       TabIndex        =   17
  179.       Top             =   2100
  180.       Width           =   585
  181.    End
  182.    Begin VB.HScrollBar Scrl_RGB 
  183.       Height          =   300
  184.       Index           =   2
  185.       LargeChange     =   10
  186.       Left            =   750
  187.       Max             =   255
  188.       TabIndex        =   6
  189.       Top             =   2220
  190.       Width           =   2550
  191.    End
  192.    Begin VB.TextBox Txt_RGB 
  193.       BackColor       =   &H00FFFFFF&
  194.       BeginProperty Font 
  195.          Name            =   "MS Sans Serif"
  196.          Size            =   7.8
  197.          Charset         =   0
  198.          Weight          =   700
  199.          Underline       =   0   'False
  200.          Italic          =   0   'False
  201.          Strikethrough   =   0   'False
  202.       EndProperty
  203.       ForeColor       =   &H00000000&
  204.       Height          =   300
  205.       Index           =   2
  206.       Left            =   3330
  207.       TabIndex        =   9
  208.       Top             =   2220
  209.       Width           =   480
  210.    End
  211.    Begin VB.PictureBox Pic_NearestSolidColor 
  212.       BeginProperty Font 
  213.          Name            =   "MS Sans Serif"
  214.          Size            =   7.8
  215.          Charset         =   0
  216.          Weight          =   700
  217.          Underline       =   0   'False
  218.          Italic          =   0   'False
  219.          Strikethrough   =   0   'False
  220.       EndProperty
  221.       Height          =   630
  222.       Left            =   4455
  223.       ScaleHeight     =   588
  224.       ScaleWidth      =   1152
  225.       TabIndex        =   11
  226.       Top             =   2445
  227.       Width           =   1200
  228.    End
  229.    Begin VB.CommandButton Cmd_OK 
  230.       Cancel          =   -1  'True
  231.       Caption         =   "&Done"
  232.       BeginProperty Font 
  233.          Name            =   "MS Sans Serif"
  234.          Size            =   7.8
  235.          Charset         =   0
  236.          Weight          =   700
  237.          Underline       =   0   'False
  238.          Italic          =   0   'False
  239.          Strikethrough   =   0   'False
  240.       EndProperty
  241.       Height          =   360
  242.       Left            =   75
  243.       TabIndex        =   12
  244.       Top             =   2640
  245.       Width           =   1305
  246.    End
  247.    Begin VB.CommandButton Cmd_Set 
  248.       Caption         =   "&Set"
  249.       Default         =   -1  'True
  250.       BeginProperty Font 
  251.          Name            =   "MS Sans Serif"
  252.          Size            =   7.8
  253.          Charset         =   0
  254.          Weight          =   700
  255.          Underline       =   0   'False
  256.          Italic          =   0   'False
  257.          Strikethrough   =   0   'False
  258.       EndProperty
  259.       Height          =   360
  260.       Left            =   1560
  261.       TabIndex        =   13
  262.       Top             =   2640
  263.       Width           =   1305
  264.    End
  265.    Begin VB.CommandButton Cmd_Reset 
  266.       Caption         =   "&Reset"
  267.       BeginProperty Font 
  268.          Name            =   "MS Sans Serif"
  269.          Size            =   7.8
  270.          Charset         =   0
  271.          Weight          =   700
  272.          Underline       =   0   'False
  273.          Italic          =   0   'False
  274.          Strikethrough   =   0   'False
  275.       EndProperty
  276.       Height          =   360
  277.       Left            =   3045
  278.       TabIndex        =   14
  279.       Top             =   2640
  280.       Width           =   1305
  281.    End
  282.    Begin VB.Label Lbl_RGBValues 
  283.       AutoSize        =   -1  'True
  284.       BackColor       =   &H00FFFFFF&
  285.       Caption         =   "RGB Values"
  286.       BeginProperty Font 
  287.          Name            =   "MS Sans Serif"
  288.          Size            =   7.8
  289.          Charset         =   0
  290.          Weight          =   700
  291.          Underline       =   0   'False
  292.          Italic          =   0   'False
  293.          Strikethrough   =   0   'False
  294.       EndProperty
  295.       ForeColor       =   &H00000000&
  296.       Height          =   195
  297.       Left            =   3360
  298.       TabIndex        =   20
  299.       Top             =   1065
  300.       Width           =   1035
  301.    End
  302.    Begin VB.Label Lbl_SelectedColor 
  303.       BackColor       =   &H00FFFFFF&
  304.       Caption         =   "Selected Color"
  305.       BeginProperty Font 
  306.          Name            =   "MS Sans Serif"
  307.          Size            =   7.8
  308.          Charset         =   0
  309.          Weight          =   700
  310.          Underline       =   0   'False
  311.          Italic          =   0   'False
  312.          Strikethrough   =   0   'False
  313.       EndProperty
  314.       ForeColor       =   &H00000000&
  315.       Height          =   375
  316.       Left            =   4605
  317.       TabIndex        =   18
  318.       Top             =   1065
  319.       Width           =   975
  320.    End
  321.    Begin VB.Label Lbl_Red 
  322.       BackColor       =   &H00FFFFFF&
  323.       Caption         =   "Red"
  324.       ForeColor       =   &H000000FF&
  325.       Height          =   300
  326.       Left            =   120
  327.       TabIndex        =   1
  328.       Top             =   1260
  329.       Width           =   600
  330.    End
  331.    Begin VB.Label Lbl_Green 
  332.       BackColor       =   &H00FFFFFF&
  333.       Caption         =   "Green"
  334.       ForeColor       =   &H00008000&
  335.       Height          =   300
  336.       Left            =   120
  337.       TabIndex        =   2
  338.       Top             =   1740
  339.       Width           =   600
  340.    End
  341.    Begin VB.Label Lbl_NearestSolidColor 
  342.       BackColor       =   &H00FFFFFF&
  343.       Caption         =   "Nearest Solid Color"
  344.       BeginProperty Font 
  345.          Name            =   "MS Sans Serif"
  346.          Size            =   7.8
  347.          Charset         =   0
  348.          Weight          =   700
  349.          Underline       =   0   'False
  350.          Italic          =   0   'False
  351.          Strikethrough   =   0   'False
  352.       EndProperty
  353.       ForeColor       =   &H00000000&
  354.       Height          =   375
  355.       Left            =   4605
  356.       TabIndex        =   19
  357.       Top             =   2070
  358.       Width           =   975
  359.    End
  360.    Begin VB.Label Lbl_Blue 
  361.       BackColor       =   &H00FFFFFF&
  362.       Caption         =   "Blue"
  363.       ForeColor       =   &H00FF0000&
  364.       Height          =   300
  365.       Left            =   120
  366.       TabIndex        =   3
  367.       Top             =   2220
  368.       Width           =   600
  369.    End
  370. End
  371. Attribute VB_Name = "ColorPalette"
  372. Attribute VB_GlobalNameSpace = False
  373. Attribute VB_Creatable = False
  374. Attribute VB_PredeclaredId = True
  375. Attribute VB_Exposed = False
  376. DefInt A-Z
  377.  
  378. Private Sub Cmd_OK_Click()
  379.     Unload ColorPalette
  380. End Sub
  381.  
  382. Private Sub Cmd_Reset_Click()
  383.     Initialize_RGB_Scrollbars
  384. End Sub
  385.  
  386. ' Places new color into the ColorPalette and Refreshes
  387. ' the color palettes so the new colors are displayed.
  388. Private Sub Cmd_Set_Click()
  389.     ' Create the Long Integer RGB value from the RGB scrollbar values, and
  390.     ' place into Color array.
  391.     Colors(ColorIndex) = RGB(Scrl_RGB(0).Value, Scrl_RGB(1).Value, Scrl_RGB(2).Value)
  392.     ' Display new ColorPalette
  393.     Display_Color_Palette Pic_ColorPalette
  394.     Display_Color_Palette Editor.Pic_ColorPalette
  395. End Sub
  396.  
  397. Private Sub Display_New_Color_And_Elements(FirstElement, LastElement)
  398.     Pic_SelectedColor.BackColor = RGB(Scrl_RGB(0).Value, Scrl_RGB(1).Value, Scrl_RGB(2).Value)
  399.     ' Since some of the drawing tools cannot use dithered colors,
  400.     ' the nearest Solid color to the actual color selected is also displayed.
  401.     Pic_NearestSolidColor.BackColor = GetNearestColor(hDC, Pic_SelectedColor.BackColor)
  402.     For i = FirstElement To LastElement
  403.         Txt_RGB(i).Text = Format$(Scrl_RGB(i).Value)
  404.         Pic_RGB(i).BackColor = Scrl_RGB(i).Value * 2 ^ (i * 8)
  405.     Next i
  406. End Sub
  407.  
  408. Private Sub Form_Load()
  409.     ColorPaletteLoaded = True
  410.     Remove_Items_From_Sysmenu ColorPalette
  411. End Sub
  412.  
  413. ' Extracts the Red, Green, and Blue elements from the
  414. ' selected ColorPalette color and assigns these values to the
  415. ' corresponding RGB Scrollbars.
  416. Private Sub Initialize_RGB_Scrollbars()
  417.     Scrl_RGB(RED_ELEMENT).Value = Colors(ColorIndex) And &HFF&
  418.     Scrl_RGB(GREEN_ELEMENT).Value = (Colors(ColorIndex) \ 2 ^ 8) And &HFF&
  419.     Scrl_RGB(BLUE_ELEMENT).Value = (Colors(ColorIndex) \ 2 ^ 16) And &HFF&
  420.     ' Display the numerical and visual values for these Elements
  421.     ' along with the selected color and its nearest solid color.
  422.     Display_New_Color_And_Elements RED_ELEMENT, BLUE_ELEMENT
  423. End Sub
  424.  
  425. Private Sub Pic_ColorPalette_GotFocus()
  426.     ' Pic_ColorPalette has a tabindex of 0, thus it receives the focus
  427.     ' first when the ColorPalette form gains the focus, so Initialization
  428.     ' is done here.
  429.     Initialize_RGB_Scrollbars
  430. End Sub
  431.  
  432. Private Sub Pic_ColorPalette_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  433.     ' Check if Mouse Coordinates are within the ColorPalette
  434.     If (X >= 0) And (X <= 16) And (Y >= 0) And (Y <= 3) Then
  435.         ' Set the Editor's current drawing color to selected color.
  436.         Update_Mouse_Colors Button, X, Y
  437.         ' Display selected color and elements of selected color
  438.         Initialize_RGB_Scrollbars
  439.     End If
  440. End Sub
  441.  
  442. Private Sub Pic_ColorPalette_Paint()
  443.     Display_Color_Palette Pic_ColorPalette
  444. End Sub
  445.  
  446. Private Sub Scrl_RGB_Change(Index As Integer)
  447.     Display_New_Color_And_Elements Index, Index
  448. End Sub
  449.  
  450. Private Sub Txt_RGB_Change(Index As Integer)
  451.     If Val(Txt_RGB(Index).Text) > 255 Then
  452.         ' A value outside the value RGB range was entered.  Beep
  453.         ' to signal the user, then reset value to previous value
  454.         Beep
  455.         Txt_RGB(Index).Text = Format$(Scrl_RGB(Index).Value)
  456.     Else
  457.         ' A valid RGB value was entered so reset corresponding RGB Scrollbar
  458.         Scrl_RGB(Index).Value = Val(Txt_RGB(Index).Text)
  459.     End If
  460.     Txt_RGB(Index).SelStart = Len(Txt_RGB(Index).Text)
  461. End Sub
  462.  
  463. Private Sub Txt_RGB_KeyPress(Index As Integer, KeyAscii As Integer)
  464.     ' Do not allow any characters other than 0123456789 to be entered.
  465.     If ((KeyAscii < 48) Or (KeyAscii > 57)) And (KeyAscii <> 8) Then
  466.         KeyAscii = 0
  467.         Beep
  468.     End If
  469. End Sub
  470.  
  471.